package com.sharer.last.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import com.sharer.last.base.utils.ConvertUtil;
import com.sharer.last.mapper.BlogTagMapper;
import com.sharer.last.mapper.CategoryMapper;
import com.sharer.last.model.po.BlogTagPO;
import com.sharer.last.model.po.CategoryPO;
import com.sharer.last.service.BlogTagService;
import com.sharer.last.utils.SecurityHelper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 文件注释地方
 *
 * @ClassName BlogTagServiceImpl
 * @Author WangJin
 * @Date 2023/06/09/16:26
 * @Description
 * @Version 1.0
 */
@Service
public class BlogTagServiceImpl extends ServiceImpl<BlogTagMapper, BlogTagPO> implements BlogTagService {
    /**
     * 获取指定标签下的博客数量
     *
     * @param tagId 标签id
     * @return
     */
    @Override
    public long getBlogNumByTagId(Long tagId) {
        LambdaQueryWrapper<BlogTagPO> qw = new LambdaQueryWrapper<>();
        qw.eq(BlogTagPO::getTagId, tagId);
        return this.count(qw);
    }

    /**
     * 查找指定标签下的博客id集合
     *
     * @param tagId
     * @return
     */
    @Override
    public List<Long> getBlogIdsByTagId(Integer tagId) {
        LambdaQueryWrapper<BlogTagPO> qw = new LambdaQueryWrapper<>();
        qw.eq(BlogTagPO::getTagId, tagId);
        List<BlogTagPO> list = this.list(qw);
        return list.stream().map(BlogTagPO::getBlogId).collect(Collectors.toList());
    }

    /**
     * 根据博客id查询数据
     *
     * @param blogId
     * @return
     */
    @Override
    public List<BlogTagPO> queryListByBlogId(Long blogId) {
        LambdaQueryWrapper<BlogTagPO> qw = new LambdaQueryWrapper<>();
        qw.eq(BlogTagPO::getBlogId, blogId);
        return this.list(qw);
    }

    /**
     * 删除指定博客id的数据
     *
     * @param blogId 博客id
     * @return
     */
    @Override
    public boolean deleteByBlogId(Long blogId) {
        LambdaQueryWrapper<BlogTagPO> qw = new LambdaQueryWrapper<>();
        qw.eq(BlogTagPO::getBlogId, blogId);
        return this.remove(qw);
    }
}
